#!/bin/bash

if [[ $# -le 0 ]]
then
	echo must supply unique session id
	exit -1
fi

sessionid=$1
dirname=`dirname $0`

. ${dirname}/meta.sh


#do cleanup
${dirname}/cleanup.sh ${sessionid}

mkdir -p  ${workdir}


#ps aux | grep -v grep | grep -v awk | 
#awk '/pipeserver|vxrefserver/{print $2}' |
#xargs kill -9 2> /dev/null

if [[ ! -p $pipein ]]; then
  mkfifo $pipein
fi

if [[ ! -p $pipeout ]]; then
  mkfifo $pipeout
fi

touch $vxreflock

$pipeserver $pipein |& 
tee $log_input |&
$xref ${options[@]} &> $pipeout  &      #start the server in the bg
                                       #listening to input on pipein

pid_xref=$!;                           #get the pid of the server

$pipeserver $pipeout |&
tee $log_output |& 
$vxrefserver -o $vxrefout -l $vxreflock &

wait $pid_xref;                        #do not quit until the server is done
